home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr14 / dndprogs.zip / NEWNAMES.AWK < prev    next >
Text File  |  1993-04-01  |  627b  |  43 lines

  1. #! /usr/local/bin/nawk -f
  2.  
  3. BEGIN {
  4.     srand()
  5.     Count[0] = 0
  6.     Section = 0
  7. }
  8.  
  9. /^%[     ]*$/ {
  10.     Section++;
  11.     Count[Section] = 0
  12.     next
  13. }
  14.  
  15. /^#.*$/ { next }  # ignore comments
  16.  
  17. /^[     ]*$/ { next } # ignore blank lines
  18.  
  19. {
  20.     Syllables[Section, Count[Section] ] = $0
  21.     Count[Section]++
  22. }
  23.  
  24. END {
  25.     for (;;) {
  26.     # random from first section
  27.     printf "[%s", Syllables[0, Rand(0, Count[0] - 1)]
  28.  
  29.     for (i = 1; i <= Section && i in Count; i++) {
  30.         if (Count[i]) {
  31.         printf "-%s", Syllables[i, Rand(0, Count[i] - 1)]
  32.         }
  33.     }
  34.  
  35.     printf "]\n"
  36.     }
  37. }
  38.  
  39. function Rand(min, max)
  40. {
  41.     return int((max + 1 - min) * rand()) + min
  42. }
  43.